package com.fly.demo.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fly.core.entity.JsonResult;
import com.fly.core.entity.PageRequest;
import com.fly.core.entity.PageResult;
import com.fly.demo.service.LoginDetailService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@CrossOrigin
@Api(tags = "Rest数据接口演示")
@RestController
@RequestMapping("/rest/data")
public class RestDataController
{
    @Autowired
    private LoginDetailService loginDetailService;
    
    @ApiOperationSupport(order = 10)
    @ApiOperation("01 批量插入")
    @PostMapping("/batchInsert")
    public JsonResult<?> batchInsert()
    {
        loginDetailService.batchInsert();
        return JsonResult.success();
    }
    
    @ApiOperationSupport(order = 30)
    @ApiOperation("03 清除全部数据")
    @PostMapping("/deleteAll")
    public JsonResult<?> deleteAll()
    {
        loginDetailService.deleteAll();
        return JsonResult.success();
    }
    
    @ApiOperationSupport(order = 20)
    @ApiOperation("02 分页查询")
    @GetMapping("/findPage")
    public JsonResult<?> findPage(@Validated PageRequest pageQuery)
    {
        PageResult pageResult = loginDetailService.findPage(pageQuery);
        return JsonResult.success(pageResult);
    }
    
}
